﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CmpEdu
{
    public partial class FrmT4_4 : Form
    {
        public FrmT4_4()
        {
            InitializeComponent();
        }

        private void FormTest4_4_Load(object sender, EventArgs e)
        {
            this.Text = "通过虚方法实现多态";
            rbCube.Checked = true;
            rBCuboid.Checked = false;
        }

        private void BtCalcCubage_Click(object sender, EventArgs e)
        {
            if (!double.TryParse(tbLength.Text,out double res1))
            {
                MessageBox.Show("未输入长度或输入了非数字","长度",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                return;
            }
            if (rbCube.Checked)
            {
                tbWidth.Text = "";
                tbHeight.Text = "";
                Cube cub = new Cube(double.Parse(tbLength.Text));
                lbResult.Text = "正方体的体积是：" + cub.CalcCubage().ToString();
            }
            else if (rBCuboid.Checked)
            {
                if (!double.TryParse(tbWidth.Text, out double res2) || !double.TryParse(tbHeight.Text, out double res3))
                {
                    MessageBox.Show("未输入宽度和高度或输入了非数字", "长度/高度", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                Cuboid cub = new Cuboid(double.Parse(tbLength.Text), double.Parse(tbWidth.Text), double.Parse(tbHeight.Text));
                lbResult.Text = "长方体的体积是：" + cub.CalcCubage().ToString();
            }
        }

        private void BtCalcCubage_MouseEnter(object sender, EventArgs e)
        {
            BtCalcCubage.Text = "点我呀！";
        }

        private void BtCalcCubage_MouseLeave(object sender, EventArgs e)
        {
            BtCalcCubage.Text = "计算体积";
        }
    }
}
